<template>
  <view class="container">
    <!-- 输入评价内容 -->
    <view class="form">
      <textarea v-model="remark" placeholder="请输入您的评价" class="textarea"></textarea>
    </view>
    <button class="submit-btn" @click="submitAppraise">提交评价</button>
  </view>
</template>

<script>
import config from "@/config.js";

export default {
  data() {
    return {
      orderId: null,
      remark: ""
    };
  },
  methods: {
    submitAppraise() {
      if (!this.remark.trim()) {
        uni.showToast({
          title: "评价内容不能为空",
          icon: "none"
        });
        return;
      }

      uni.request({
        url: `${config.apiUrl}/order/submitRemark`,
        method: "POST",
        header: {
          "Content-Type": "application/json"
        },
        data: {
          orderId: this.orderId,
          remark: this.remark
        },
        success: (response) => {
          if (response.statusCode === 200) {
            uni.showToast({
              title: "评价成功",
              icon: "success"
            });
            // 返回上一页
            uni.navigateBack();
          } else {
            uni.showToast({
              title: "评价失败",
              icon: "none"
            });
          }
        },
        fail: (error) => {
          console.error("提交评价请求失败", error);
          uni.showToast({
            title: "请求失败，请重试",
            icon: "none"
          });
        }
      });
	  
    }
  },
  onLoad(options) {
    this.orderId = options.orderId;
  }
};
</script>

<style>
.container {
  padding: 50rpx;
  height: 100%;
  background-color: #ffffff;
}

.form {
  margin-top: 20rpx;
}

.textarea {
  width: 100%;
  height: 300rpx;
  padding: 20rpx;
  border: 1px solid #ddd;
  border-radius: 10rpx;
  font-size: 30rpx;
}

.submit-btn {
  margin-top: 20rpx;
  padding: 20rpx;
  background-color: #ff5400;
  color: #ffffff;
  text-align: center;
  border-radius: 10rpx;
  font-size: 30rpx;
  cursor: pointer;
}
</style>
